//
//  CTPublishTypePickView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/5/21.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTPublishTypePickView.h"
#import "CTDebugManager.h"
#import "CTHeader.h"
#import "CTAppLanguage.h"

@implementation CTPublishTypePickView
@synthesize delegate;

- (void)dealloc
{
    delegate = nil;
    
    [CTDebugManager showDebugLogInfo:@"dealloc : CTPublishTypePickView Is Removed!!!"];
}

- (instancetype)init
{
    self = [super init];
    if (self) {
   
        self.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT);
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = YES;
        
        [self creatSubviews];
    }
    return self;
}

-(void)creatSubviews
{
    UIView * shadowView = [[UIView alloc] initWithFrame:self.bounds];
    shadowView.backgroundColor = [UIColor blackColor];
    shadowView.alpha = 0.8;
    shadowView.userInteractionEnabled = YES;
    [self addSubview:shadowView];
    
    UIButton * cancelBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-44, 20, 44, 44);
    [cancelBtn addTarget:self action:@selector(cancelBtn:) forControlEvents:UIControlEventTouchUpInside];
    [cancelBtn setTitleColor:CT_HEADER_WHITE_COLOR forState:UIControlStateNormal];
    [cancelBtn setBackgroundImage:[UIImage imageNamed:@"quxiao"] forState:UIControlStateNormal];
    [self addSubview:cancelBtn];
    
    
    for (int i = 0; i < 2; i ++) {
        UIButton * publishTypeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        publishTypeBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-153, 69+i*60, 140, 45);
        [publishTypeBtn setBackgroundImage:[UIImage imageNamed:@"bg"] forState:UIControlStateNormal];
        [publishTypeBtn setBackgroundImage:[UIImage imageNamed:@"bg_click"] forState:UIControlStateHighlighted];
        [publishTypeBtn addTarget:self action:@selector(publishBtn:) forControlEvents:UIControlEventTouchUpInside];
        publishTypeBtn.tag = i;
        [self addSubview:publishTypeBtn];
        
        
        UIImageView * publishTypeImageview = [[UIImageView alloc] initWithFrame:CGRectMake(22, 12, 21, 21)];
        [publishTypeBtn addSubview:publishTypeImageview];
        
        
        UILabel * publishTypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 80, 45)];
        publishTypeLabel.font = [UIFont systemFontOfSize:18];
        publishTypeLabel.textColor = CT_HEADER_BLACK_COLOR;
        [publishTypeBtn addSubview:publishTypeLabel];
        
        switch (i) {
            case 0:
                publishTypeLabel.text = [CTAppLanguage localizedStringForKey:@"publishTypePickView_publishType_emoji" withValue:nil withTable:@"Language"];
                
                publishTypeImageview.image = [UIImage imageNamed:@"fabiaoqing"];
                
                break;
            case 1:
                publishTypeLabel.text = [CTAppLanguage localizedStringForKey:@"publishTypePickView_publishType_photo" withValue:nil withTable:@"Language"];
                
                publishTypeImageview.image = [UIImage imageNamed:@"fazhaopian"];
                
                break;
            default:
                break;
        }
        
    }
}

#pragma mark - action & delegate -

-(void)publishBtn:(id)sender
{
    UIButton * btn = (UIButton *)sender;
    CTPublishType  publishType = CTPublishTypeNone;
  
    NSInteger tag = btn.tag;
    switch (tag) {
        case 0:
            //emoji
            publishType = CTPublishTypeEmoji;
            break;
        case 1:
            //photo
            publishType = CTPublishTypePhoto;
            break;
        default:
            break;
    }
    
    if ([self.delegate respondsToSelector:@selector(publishClickedAction:withType:)]) {
        [self.delegate publishClickedAction:self withType:publishType];
    }
    
}
-(void)cancelBtn:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(publishCancelAction:)]) {
        [self.delegate publishCancelAction:self];
    }
    [self removeFromSuperview];
}

@end
